package com.cskaoyan.service.admin.impl;

import com.cskaoyan.bean.BaseParamBo;
import com.cskaoyan.bean.BaseRespData;
import com.cskaoyan.bean.pojo.Log;
import com.cskaoyan.bean.pojo.LogExample;
import com.cskaoyan.mapper.LogMapper;
import com.cskaoyan.service.admin.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class LogServiceImpl implements LogService {

    @Autowired
    LogMapper logMapper;


    @Override
    public BaseRespData query(String name, BaseParamBo param) {
        PageHelper.startPage(param.getPage(),param.getLimit());

        LogExample logExample = new LogExample();
        logExample.setOrderByClause(param.getSort() +" " +param.getOrder());

        LogExample.Criteria criteria = logExample.createCriteria();

        if(name != null && !"".equals(name)){
            criteria.andAdminLike("%" + name + "%");
        }
        criteria.andDeletedEqualTo(false);

        List<Log> logList = logMapper.selectByExample(logExample);

        PageInfo<Log> logPageInfo = new PageInfo<>(logList);
        long total = logPageInfo.getTotal();

        return BaseRespData.create(logList,total);
    }
}
